package com.jtuixueyuan.service.impl;

import com.jtuixueyuan.service.BuyActionService;
import com.jutixueyuan.pojo.House;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class BuyActionServiceImpl implements BuyActionService {


    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public Map<String, Object> getBuyTimeByHouseId(String id) {
        Map<String, Object> result = new HashMap<>();
        try {
            //根据id查询出House
            House house = mongoTemplate.findById(id, House.class);

            //获取购买时间的时间戳
            long buytime = house.getBuytime().getTime();


            result.put("time", buytime);
            result.put("status", 200);
        } catch (Exception e) {
            result.put("msg", "请求失败");
            result.put("status", 500);
        }
        return result;
    }
}
